import wxHttp from "@/utils/wxRequest";
import {isString} from "@/utils/validate";

export function uploadFile(file, onProgress) {
  return wxHttp.upload('/common/upload/server', file, onProgress)
}

export function fileUpValidate(file, types, that) {
  if (!types.length) return true
  let name = file.name
  let suff = name.substring(name.lastIndexOf('.') + 1)
  if (isString(types)) {
    types = types.split(",")
  }
  if (!types.includes(suff)) {
    that.$message.error('文件：「' + name + '」格式错误')
    return false
  }
  return true
}

export function isPictureLoad(t) {
  if (!t) return false
  const imgSuff = ['png', 'jpg', 'jpeg']
  if (isString(t)) {
    t = t.split(",")
  }
  for (let i = 0; i < t.length; i++) {
    if (!imgSuff.includes(t[i])) {
      return false;
    }
  }
  return true
}
